<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="seatList" stripe border class="tableBox">
      <el-table-column label="序号" type="index" width="80" />
      <el-table-column label="会员等级" prop="vipCode" width="150" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.vipCode == 'GOLD'">金牌</span>
          <span v-if="scope.row.vipCode == 'SILVER'">银牌</span>
        </template>
      </el-table-column>
      <el-table-column label="时长" prop="dayLadder" width="150" align="center">
        <!-- <template slot-scope="scope">
          <span v-if="scope.row.dayLadder == 'ONE'">一天</span>
          <span v-if="scope.row.dayLadder == 'WEEK'">一周</span>
          <span v-if="scope.row.dayLadder == 'MONTH'">一月</span>
        </template> -->
      </el-table-column>
      <el-table-column label="现金价" prop="cashPrice" width="150" align="center" />
      <el-table-column label="金积分价" prop="goldPrice" width="150" align="center" />
      <el-table-column label="银积分价" prop="silverPrice" width="150" align="center" />
      <el-table-column label="排序" prop="orderNum" width="150" align="center" />
      <el-table-column label="是否启用" prop="useState" align="center" class-name="fixed-width" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          {{scope.row.useState == 1?'启用':'停用'}}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="150">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['basics:seat:edit']">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" /> -->

    <!-- 编辑席位对话框 -->
    <Z-Dialog :title="title" :visible.sync="open" @confirm="submitForm">
      <el-form ref="form" :model="form" label-width="100px" :rules="rules">
        <el-form-item label="会员等级" prop="vipCode">
          <el-select v-model="form.vipCode" placeholder="会员等级" clearable style="width:100%">
            <el-option v-for="dict in this.vipCode" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="时长" prop="dayLadder">
          <el-select v-model="form.dayLadder" placeholder="上架状态" clearable style="width:100%">
            <el-option v-for="dict in this.dayLadder" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="现金价" prop="cashPrice">
          <el-input v-model="form.cashPrice" placeholder="请输入现金价" />
        </el-form-item>
        <el-form-item label="金积分价" prop="goldPrice">
          <el-input v-model="form.goldPrice" placeholder="请输入金积分价" />
        </el-form-item>
        <el-form-item label="银积分价" prop="silverPrice">
          <el-input v-model="form.silverPrice" placeholder="请输入银积分价" />
        </el-form-item>
        <el-form-item label="排序" sortable prop="orderNum">
          <el-input-number v-model="form.orderNum" controls-position="right" :min="1" />
        </el-form-item>
        <el-form-item label="是否上架" prop="useState">
          <el-select v-model="form.useState" placeholder="上架状态" clearable style="width:100%">
            <el-option v-for="dict in this.useState" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
      </el-form>
    </Z-Dialog>

  </div>
</template>

<script>
import { listViplevelprice, editViplevelprice, listDayLadder } from "@/api/basics/seat.js";
import { deepClone } from '@/utils/index'

export default {
  name: "seat", //席位
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      seatList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: this.global.pageSize,
        informationName: undefined,

      },
      // 表单参数
      form: {},

      vipCode: [{ label: '金牌', value: 'GOLD' }, { label: '银牌', value: 'SILVER' }],
      dayLadder: [{ label: '一天', value: 'ONE' }, { label: '一周', value: 'WEEK' }, { label: '一月', value: 'MONTH' },],
      useState: [{ label: '启用', value: 1 }, { label: '停用', value: 0 }],
      rules: {
        vipCode: [{ required: true, message: "必填", trigger: "blur" }],
        dayLadder: [{ required: true, message: "必填", trigger: "blur" }],
        silverPrice: [{ required: true, message: "必填", trigger: "blur" }],
        goldPrice: [{ required: true, message: "必填", trigger: "blur" }],
        cashPrice: [{ required: true, message: "必填", trigger: "blur" }],
        useState: [{ required: true, message: "必填", trigger: "blur" }],

      }
    };
  },
  created() {
    this.getListDayLadder();
  },
  methods: {
    getList() {
      this.loading = true;
      listViplevelprice(this.queryParams)
        .then((response) => {
          if (response.code == 200) {
            this.seatList = response.data;
            this.total = response.total;
          }
          this.loading = false;
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    getListDayLadder() {
      let _this = this;
      listDayLadder()
        .then((response) => {
          if (response.code == 200) {
            this.dayLadder = response.data.dayLadder;
            this.dayLadder.forEach(item => {
              item.label = item.remark;
              item.value = item.text
            });
            this.vipCode = response.data.vipLevel;
            this.vipCode.forEach(item => {
              item.label = item.text
              // item.value = item.remark,
            });

            _this.getList();
          }

        })
        .catch((err) => {

        });

    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    // 表单重置
    reset() {
      this.resetForm("form");
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.open = true;
      this.form = deepClone(row);
      this.title = "编辑席位";
    },

    /** 提交按钮 */
    submitForm: function () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            editViplevelprice(this.form).then((response) => {
              this.$modal.msgSuccess("编辑成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  },
};
</script>
<style lang="scss">
.el-tooltip__popper {
  max-width: 50%;
}

.tableBox {
  th {
    padding: 0 !important;
    height: 48px;
    line-height: 48px;
  }
  td {
    
    padding: 0 !important;
    height: 48px;
    line-height: 48px;
  }
}
</style>

